package com.zr.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.zr.dao.LinkDao;
import com.zr.model.Web_site;
import com.zr.util.GetJDBCUtil;

import net.sf.json.JSONArray;

public class LinkDaoImpl implements LinkDao{

	GetJDBCUtil gt = new GetJDBCUtil();
	
	@Override
	public JSONArray getLink() {
		Connection con = gt.getJDBCConnection();
		
		JSONArray jArray = new JSONArray();
		
		StringBuffer sql = new StringBuffer(""); 
		sql.append("SELECT wid,wname,wlink ");
		sql.append("FROM e_web_site ");
		
		try {
			PreparedStatement pst = con.prepareStatement(sql.toString());
			
			ResultSet rs = pst.executeQuery();
			
			while(rs.next()){
				Web_site wSite = new Web_site();
				wSite.setWid(rs.getInt("wid"));
				wSite.setWname(rs.getString("wname"));
				wSite.setWlink(rs.getString("wlink"));
				jArray.add(wSite);
			}
			
			rs.close();
			pst.close();
			con.close();
		
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return jArray;
	}

}
